package com.gcxy.exception.handler;

import com.gcxy.core.R;
import com.gcxy.enums.ResultCodeEnum;
import com.gcxy.exception.annotation.GlobalException;
import com.gcxy.exception.global.IGlobalException;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.BatchUpdateException;

/**
 * Copyright (C), 2024-2024, BUG闭退！
 * Author: Huang先森
 * Date: 2024/7/22 13:19
 * FileName: BatchUpdateExceptionHandler
 * Description: 数据库批量修改异常

 */
@Slf4j
@GlobalException(throwable = BatchUpdateException.class)
public class BatchUpdateExceptionHandler implements IGlobalException<R, BatchUpdateException> {

    @Override
    public R exception(BatchUpdateException throwable, HttpServletRequest request, HttpServletResponse response) {
        log.error(throwable.getMessage());
        return R.Failed(ResultCodeEnum.DUPLICATE_KEY_EXCEPTION.getCode(), "数据已存在，请勿重复操作");
    }
}